1 using UnityEngine;
2 using
System.Collections;
3
4 public
abstract class TemporalAction : Action {
5
6     
private float duration, time;
7     
private InterpolationProcess interpolationProcess;
8     
private bool reverse, began, complete;
9     
private float percent;
10     
/*
11     
public TemporalAction() { }
12     
public TemporalAction(float duration) {
13         
this.duration = duration;
14     }
15     
public TemporalAction(float duration, Interpolation interpolation)
16     {
17         
this.duration = duration;
18         
this.interpolation = interpolation;
19     }
20      * */

21
22     
public override bool Act(float delta)
23     {
24         
if (complete) return true;
25
26         
try
27         {
28             
if (!began)
29             {
30                 begin();
31                 began =
true;
32             }
33             time += delta;
34             complete = time >= duration;
35             
if (complete) percent = 1;
36             
else
37             {
38                 percent = time / duration;
39                 
if (interpolationProcess != null) percent = interpolationProcess.apply(percent);
40             }
41             
//UpdateAction(reverse ? 1 - percent : percent);
42             UpdateAction(percent);
43             
if (complete) {
44                 end();
45             }
46             
return complete;
47         }
48         
finally {
49             
//return false;
50         }
51     }
52
53     
protected abstract void begin();
54
55     
protected abstract void end();
56
57     
protected abstract void UpdateAction(float percent);
58
59     
public void SetDuration(float duration)
60     {
61         
this.duration = duration;
62     }
63
64     
public void SetInterpolation(Interpolation interpolation)
65     {
66         
this.interpolationProcess = InterpolationProcess.createInterpolation(interpolation);
67     }
68
69     
public override void restart()
70     {
71         time =
0;
72         began =
false;
73         complete =
false;
74     }
75
76     
public virtual void finish()
77     {
78         time = duration;
79     }
80 }


UpdateAction(reverse ? 1 - percent : percent);

return false;




Trò chơi đua xe động vật trong UNITY Engine 114.745 lượt xem

Gõ tìm kiếm nhanh...